package cn.iocoder.yudao.module.project.controller.admin.weightthresholdmanage;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.project.controller.admin.weightthresholdmanage.vo.*;
import cn.iocoder.yudao.module.project.dal.dataobject.weightthresholdmanage.WeightThresholdManageDO;
import cn.iocoder.yudao.module.project.service.weightthresholdmanage.WeightThresholdManageService;

@Tag(name = "管理后台 - 重量阈值管理")
@RestController
@RequestMapping("/project/weight-threshold-manage")
@Validated
public class WeightThresholdManageController {

    @Resource
    private WeightThresholdManageService weightThresholdManageService;

    @PostMapping("/create")
    @Operation(summary = "创建重量阈值管理")
    @PreAuthorize("@ss.hasPermission('project:weight-threshold-manage:create')")
    public CommonResult<String> createWeightThresholdManage(@Valid @RequestBody WeightThresholdManageSaveReqVO createReqVO) {
        return success(weightThresholdManageService.createWeightThresholdManage(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新重量阈值管理")
    @PreAuthorize("@ss.hasPermission('project:weight-threshold-manage:update')")
    public CommonResult<Boolean> updateWeightThresholdManage(@Valid @RequestBody WeightThresholdManageSaveReqVO updateReqVO) {
        weightThresholdManageService.updateWeightThresholdManage(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除重量阈值管理")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('project:weight-threshold-manage:delete')")
    public CommonResult<Boolean> deleteWeightThresholdManage(@RequestParam("id") String id) {
        weightThresholdManageService.deleteWeightThresholdManage(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得重量阈值管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('project:weight-threshold-manage:query')")
    public CommonResult<WeightThresholdManageRespVO> getWeightThresholdManage(@RequestParam("id") String id) {
        WeightThresholdManageDO weightThresholdManage = weightThresholdManageService.getWeightThresholdManage(id);
        return success(BeanUtils.toBean(weightThresholdManage, WeightThresholdManageRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得重量阈值管理分页")
    @PreAuthorize("@ss.hasPermission('project:weight-threshold-manage:query')")
    public CommonResult<PageResult<WeightThresholdManageRespVO>> getWeightThresholdManagePage(@Valid WeightThresholdManagePageReqVO pageReqVO) {
        PageResult<WeightThresholdManageDO> pageResult = weightThresholdManageService.getWeightThresholdManagePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WeightThresholdManageRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出重量阈值管理 Excel")
    @PreAuthorize("@ss.hasPermission('project:weight-threshold-manage:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportWeightThresholdManageExcel(@Valid WeightThresholdManagePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WeightThresholdManageDO> list = weightThresholdManageService.getWeightThresholdManagePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "重量阈值管理.xls", "数据", WeightThresholdManageRespVO.class,
                        BeanUtils.toBean(list, WeightThresholdManageRespVO.class));
    }




    @PostMapping("/save")
    @Operation(summary = "保存重量阈值管理")
    public CommonResult<String> saveWeightThresholdManage(@Valid @RequestBody WeightThresholdManageSaveReqVO reqVO) {
        return success(weightThresholdManageService.saveWeightThresholdManage(reqVO));
    }
}